package com.javacommunity.model.entity;

// Generated Nov 29, 2014 9:30:36 AM by Hibernate Tools 3.4.0.CR1
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * Tag generated by hbm2java
 */
@Entity
@Table(name = "tag", catalog = "db_javadanang", uniqueConstraints = @UniqueConstraint(columnNames = "tagName"))
public class Tag implements java.io.Serializable {

    private Integer tagId;
    private String tagName;
    private boolean active;
    private List<Question> questions = new ArrayList<Question>();

    public Tag() {
    }

    public Tag(String tagName, boolean active) {
        this.tagName = tagName;
        this.active = active;
    }

    public Tag(Integer tagId, String tagName, boolean active, List<Question> questions) {
        this.tagId = tagId;
        this.tagName = tagName;
        this.active = active;
        this.questions = questions;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "tagId", unique = true, nullable = false)
    public Integer getTagId() {
        return tagId;
    }

    public void setTagId(Integer tagId) {
        this.tagId = tagId;
    }

    @Column(name = "tagName", unique = true, nullable = false, length = 45)
    public String getTagName() {
        return tagName;
    }

    public void setTagName(String tagName) {
        this.tagName = tagName;
    }

    @Column(name = "active", nullable = false)
    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @ManyToMany(fetch = FetchType.EAGER, mappedBy = "tags")
    @Fetch (FetchMode.SELECT)
    public List<Question> getQuestions() {
        return questions;
    }

    public void setQuestions(List<Question> questions) {
        this.questions = questions;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Tag) {
            Tag player = (Tag) obj;
            if (this.tagId.equals(player.getTagId())) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.tagId.hashCode();
    }

}
